#include <iostream>
using namespace std;


//  Definition for a binary tree node.
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    int height(TreeNode* root)
    {
        if(root == NULL)
            return 0;
        int leftHeight = height(root->left);
        int rightHeight = height(root->right);
        if(leftHeight == -1 || rightHeight == -1 || abs(leftHeight - rightHeight) > 1)
            return -1;
        else
        {
            return max(rightHeight, leftHeight) + 1;
        }
    }
    bool isBalanced(TreeNode* root) {
        return height(root) >= 0;
    }
};

int main()
{
    return 0;
}